package conf

import (
	"github.com/spf13/viper"
	"strings"
)

func LoadFromYamlBytes(file string, v any) error {
	viper.SetConfigType("yaml")
	viper.AddConfigPath(file[:strings.LastIndex(file, "/")+1])
	filename := file[strings.LastIndex(file, "/")+1 : strings.LastIndex(file, ".")]
	viper.SetConfigName(filename)

	if err := viper.ReadInConfig(); err != nil {
		return err
	}
	if err := viper.Unmarshal(v); err != nil {
		return err
	}

	return nil
}
